package com.wgj.android.web;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AlertDialog;
import android.webkit.WebView;

import com.jiaai.xui.XUI;
import com.jiaai.xui.jsbridge.BridgeWebView;
import com.jiaai.xui.jsbridge.BridgeWebViewClient;
import com.jiaai.xui.utils.XAppUtils;
import com.jiaai.xui.view.widget.loadingview.XLoadingView;
import com.wgj.android.web.entity.WebConfig;

/**
 * Created by Administrator on 2017/10/27.
 */

public class WGJWebClient extends BridgeWebViewClient {


    public WGJWebClient(BridgeWebView webView) {
        super(webView);

    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
    }

    @Override
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        super.onReceivedError(view, errorCode, description, failingUrl);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        final Context context=view.getContext();
            if(openWithWevView(url)){
                Intent intent=new Intent(XUI.getContext(),WGJWebActivity.class);
                WebConfig webConfig=new WebConfig(url,"",1);
                Bundle bundle=new Bundle();
                bundle.putSerializable(WGJWebActivity.WEB_CONFIG,webConfig);
                intent.putExtras(bundle);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                XUI.getContext().startActivity(intent);
                return true;
            }
           return  super.shouldOverrideUrlLoading(view,url);
    }

    protected boolean openWithWevView(String url) {//处理判断url的合法性
// TODO Auto-generated method stub
        if (url.startsWith("http:") || url.startsWith("https:")) {
            return true;
        }
        return false;
    }


}
